import java.awt.event.*;

import javax.swing.*;

public class FormDatos extends JFrame implements ActionListener {
	
	private JLabel labelMatricula, labelMarca, labelModelo, labelPlaza, txtMatricula, txtMarca, txtModelo, labelMinusvalido;	
	private JButton btnSacar;
	private int x, y;
	private ImageIcon imgMinusvalido;	

	public FormDatos(int pos1, int pos2) {
		this.setLayout(null);
		this.setBounds(600, 600, 250, 300);
		this.setResizable(false);
		this.imgMinusvalido = new ImageIcon("src/minusvalido.gif");
		
		this.x = pos1;
		this.y = pos2;
		this.colocarComponentes();
	}
	
	public void colocarComponentes() {
		labelMatricula = new JLabel("Matricula");
		labelMatricula.setBounds(40, 20, 100, 25);
		this.add(labelMatricula);
		txtMatricula = new JLabel(GestorParking.obtenerVehiculo(x, y).getMatricula());
		txtMatricula.setBounds(130, 20, 100, 25);
		this.add(txtMatricula);
		
		labelMarca = new JLabel("Marca");
		labelMarca.setBounds(40, 55, 100, 25);
		this.add(labelMarca);
		txtMarca = new JLabel(GestorParking.obtenerVehiculo(x, y).getMarca());
		txtMarca.setBounds(130, 55, 100, 25);
		this.add(txtMarca);
			
		labelModelo = new JLabel("Modelo");
		labelModelo.setBounds(40, 90, 100, 25);
		this.add(labelModelo);
		txtModelo = new JLabel(GestorParking.obtenerVehiculo(x, y).getModelo());
		txtModelo.setBounds(130, 90, 100, 25);
		this.add(txtModelo);
		
		labelPlaza = new JLabel("Plaza: "+(x+1)+" - "+(y+1));
		labelPlaza.setBounds(70, 130, 100, 25);
		this.add(labelPlaza);		
		
		btnSacar = new JButton("Sacar");
		btnSacar.setBounds(70, 230, 100, 25);
		this.add(btnSacar);
		btnSacar.addActionListener(this);
		
		labelMinusvalido = new JLabel(imgMinusvalido);
		labelMinusvalido.setBounds(95, 160, 50, 50);
		this.add(labelMinusvalido);
		labelMinusvalido.setVisible(false);
		if (GestorParking.obtenerVehiculo(x, y).isMinusvalido()) {
			labelMinusvalido.setVisible(true);
		}
	}


	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == btnSacar) {
			GestorParking.sacarVehiculo(txtMatricula.getText());
		}		
	}
}
